import time

from excel_handler import ExcelHandler
from inca_controller import IncaController
from logger import DataLogger


def main():
    # 初始化模块
    logger = DataLogger()
    excel = ExcelHandler(r'inca.xlsx')
    controller = IncaController()
    #  Excel inca 变量名赋值给python
    name_value = "UDC_swtSetP_C"
    time_value = "tiem"
    # 从Excel读取标定参数并写入INCA
    cal_data = excel.read_calibration_data()
    print(cal_data)
    for item in cal_data:
        try:
            time.sleep(item[time_value])
            controller.write_calibration(name_value, item[name_value], item[time_value])
            # controller.write_calibration(item['name1'], item['name1_value'],item['time_value'])
            # logger.log_operation('EXCEL_IMPORT', item['name'],  item['name_value'], 'IMPORTED')

        except:
            print("暂停")
            break
    # 保存测量数据到Excel
    # measure_data = [{'name': 'Oil_pSwmp', 'value': controller.read_measurement('Oil_pSwmp')}]
    # excel.save_measurement_data(measure_data)


if __name__ == "__main__":
    main()
